package com.atguigu.edupublisher.controller;

import com.atguigu.edupublisher.service.SugarService;
import com.atguigu.edupublisher.utils.DateFormatUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sugar")
public class SugarController {

    @Autowired
    private SugarService sugarService;

    @RequestMapping("/provinceOrderAmount")
    public String getProvinceOrderAmount(@RequestParam(value = "date", defaultValue = "0") int date){

        if (date == 0) {
            date = getToday();
        }

        System.out.println("-->:"+date);

        return "{\n" +
                "  \"status\": 0,\n" +
                "  \"msg\": \"\",\n" +
                "  \"data\": {\n" +
                "    \"mapData\": [\n" +
                "      {\n" +
                "        \"name\": \"澳门\",\n" +
                "        \"value\": "+sugarService.getProvinceOrderAmount(date)+",\n" +
                "        \"sizeValue\": 603,\n" +
                "        \"type\": 3,\n" +
                "        \"tooltipValues\": [\n" +
                "          87,\n" +
                "          8\n" +
                "        ],\n" +
                "        \"url\": \"sugar.baidu.com\"\n" +
                "      }\n" +
                "    ]\n" +
                "  }\n" +
                "}";

    }

    private int getToday() {
        return Integer.parseInt(DateFormatUtil.toDate(System.currentTimeMillis()).replace("-", ""));
    }
}
